home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / creation_clause.e < prev    next >
Text File  |  1998-01-16  |  4KB  |  179 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class CREATION_CLAUSE
  17. --
  18. -- The store the contents of one creation clause.
  19. --   example 1
  20. --                creation {ANY} make
  21. --   example 2
  22. --                creation make, foo
  23. --   example 3
  24. --                creation {NONE,ANY} make, foo
  25. --   example 4
  26. --                creation
  27. -- 
  28. -- Note : The original text of the source file can be stored
  29. --        for pretty pretty_printing to be fine.
  30. --
  31.  
  32. inherit GLOBALS;
  33.  
  34. creation make
  35.    
  36. feature
  37.  
  38.    start_position: POSITION;
  39.      -- Of the corresponding keyword.
  40.  
  41.    clients: CLIENT_LIST;
  42.  
  43.    comment: COMMENT;
  44.  
  45. feature {NONE}
  46.  
  47.    procedure_list: FEATURE_NAME_LIST;
  48.    
  49. feature
  50.    
  51.    make(sp: like start_position; c: like clients; cm: like comment;
  52.     pl: ARRAY[FEATURE_NAME]) is
  53.       require
  54.      sp /= Void;
  55.      c /= Void;
  56.      pl /= Void implies not pl.empty;
  57.       do
  58.      start_position := sp;
  59.      clients := c;
  60.      comment := cm;
  61.      if pl /= Void then
  62.         !!procedure_list.make(pl);
  63.      end;
  64.       ensure
  65.      clients = c;
  66.      comment = cm
  67.       end;
  68.  
  69.    pretty_print is
  70.       local
  71.      i: INTEGER;
  72.       do
  73.      fmt.set_indent_level(0);
  74.      if not fmt.zen_mode then
  75.         fmt.skip(1);
  76.      else
  77.         fmt.indent;
  78.      end;
  79.      fmt.keyword("creation");
  80.      fmt.set_indent_level(1);
  81.      if clients /= Void then
  82.         clients.pretty_print;
  83.      end;
  84.      if comment /= void then
  85.         comment.pretty_print;
  86.      end;
  87.      fmt.set_indent_level(1);
  88.      if not fmt.zen_mode then
  89.         fmt.indent;
  90.      end;
  91.      if procedure_list /= Void then
  92.         procedure_list.pretty_print;
  93.      end;
  94.       end;
  95.          
  96.    short(heading_done: BOOLEAN): BOOLEAN is
  97.      -- True when at least one creation list is printed.
  98.       do
  99.      if clients.gives_permission_to_any then
  100.         if not heading_done then
  101.            short_print.hook_or("hook100","creation%N");
  102.         end;
  103.         procedure_list.short_for_creation;
  104.         short_print.hook_or("hook101","");
  105.         Result := true;
  106.      else
  107.         eh.cancel;
  108.      end;
  109.       end;
  110.  
  111.    has(fn: FEATURE_NAME): BOOLEAN is
  112.       require
  113.      fn /= Void
  114.       do
  115.      if procedure_list /= Void then
  116.         Result := procedure_list.has(fn);
  117.      end;
  118.       end;
  119.    
  120. feature {CREATION_CLAUSE_LIST}
  121.    
  122.    check_expanded_with(t: TYPE) is
  123.       require
  124.      t.is_expanded;
  125.       local
  126.      rf: RUN_FEATURE;
  127.      rf3: RUN_FEATURE_3;
  128.      rc: RUN_CLASS;
  129.       do
  130.      if procedure_list = Void then
  131.         eh.add_position(start_position);
  132.         fatal_error("Cannot create a class with an empty creation list.");
  133.      end;
  134.      if procedure_list.count > 1 then
  135.         eh.add_type(t,fz_cbe);
  136.         eh.add_position(start_position);
  137.         fatal_error_vtec_2;
  138.      end;
  139.      rc := t.run_class;
  140.      rf := rc.get_feature(procedure_list.item(1));
  141.      if rf = Void then
  142.         eh.add_position(start_position);
  143.         eh.append("Creation procedure for ");
  144.         eh.add_type(t," not found.");
  145.         eh.print_as_fatal_error;
  146.      end;
  147.      rf3 ?= rf;
  148.      if rf3 = Void then
  149.         eh.add_position(start_position);
  150.         eh.add_position(rf.start_position);
  151.         fatal_error("Feature found is not a procedure.");
  152.      end;
  153.      if rf3.arg_count > 0 then
  154.         eh.add_type(t,fz_cbe);
  155.         eh.add_position(start_position);
  156.         eh.add_position(rf3.start_position);
  157.         eh.append("Procedure found has arguments. ");
  158.         fatal_error_vtec_2;
  159.      end;   
  160.       end;
  161.    
  162.    expanded_initializer(t: TYPE): RUN_FEATURE_3 is
  163.       require
  164.      t.is_expanded;
  165.      not t.is_basic_eiffel_expanded;
  166.      procedure_list.count = 1;
  167.       do
  168.      if procedure_list /= Void then
  169.         Result ?= t.run_class.get_feature(procedure_list.item(1));
  170.      end;
  171.       end;
  172.    
  173. invariant
  174.    
  175.    clients /= Void;
  176.    
  177. end -- CREATION_CLAUSE
  178.  
  179.